#pragma once

#include "Serializable.h"
#include "PeopleData.h"
#include "Vectors.h"
#include "Types.h"
#include "StlStringAndStreams.h"

const STL::string EvalToStr(const size_t i_eval);

struct PeopleHistoryRecord
{
	PeopleHistoryRecord(const size_t i_numSeason = 1,
				  const int i_teamID = Utilities::INVALID_ID,
				  const size_t i_matchPlayed = 0,
				  const size_t i_goalScored = 0,
				  const size_t i_evaluations = 0,
				  const size_t i_redCard = 0,
				  const size_t i_yellowCard = 0,
				  const size_t i_numOfInjury = 0,
				  const size_t i_numOfInjuryDays = 0,
				  const size_t i_manOfTheMatch = 0)
			:m_numSeason(i_numSeason), m_teamID(i_teamID), m_matchPlayed(i_matchPlayed), m_goalScored(i_goalScored)
			,m_evaluations(i_evaluations), m_redCard(i_redCard), m_yellowCard(i_yellowCard)
			,m_numOfInjury(i_numOfInjury), m_numOfInjuryDays(i_numOfInjuryDays), m_manOfTheMatch(i_manOfTheMatch)
	{
	}

	const float GetRatio() const
	{
		return (m_matchPlayed == 0 ? -1.0f : static_cast<float>(m_goalScored) / static_cast<float>(m_matchPlayed));
	}

	const size_t GetEvaluation() const
	{
		return (m_matchPlayed == 0 ? 0 : m_evaluations/m_matchPlayed);
	}

	const size_t GetEval() const
	{
		return (m_matchPlayed == 0 ? 0 : m_evaluations/m_matchPlayed);
	}
	
	const STL::string GetEvalStr() const
	{
		return EvalToStr(GetEval());
	}

	void Serialize(ZStream& o_stream) const;
	void Deserialize(ZStream& i_stream);

	size_t m_numSeason;
	int m_teamID;
	size_t m_matchPlayed;
	size_t m_goalScored;
	size_t m_evaluations;
	size_t m_redCard;
	size_t m_yellowCard;
	size_t m_numOfInjury;
	size_t m_numOfInjuryDays;
	size_t m_manOfTheMatch;
};

class PeopleHistory : public Serializable
{
public:
	PeopleHistory();

	void Clear();
	void addHistoryEntry(const PeopleHistoryRecord&);
	const int GetNumHistoryEntry() const;

	const PeopleHistoryRecord& GetRecord(int i_index) const;

	void AddMatch(const int i_scoredGoals, const int i_evaluation, const bool i_isMoM, const int i_card, const int i_dayInjury);

	const size_t GetMatch() const; // current season (played or trained)
	const size_t GetTotalMatch(const int i_status) const; //StatusPlayer(played) , StatusTrainer(trained) , StatusRetired(all: played + trained)

	const size_t GetEval() const;
	const STL::string GetEvalStr() const;
	const size_t GetTotalEval() const;
	const STL::string GetTotalEvalStr() const;

	const int GetMoM() const;
	const int GetTotalMoM() const;

	const size_t GetScoredGoal() const;
	const size_t GetTotalScoredGoal() const;
	const float GetScoredGoalRatio() const;
	const float GetTotalScoredGoalRatio() const;

	const int GetNumOfInjury() const;
	const int GetNumOfInjuryDays() const;
	const int GetTotalNumOfInjury() const;
	const int GetTotalNumOfInjuryDays() const;

	const int GetRedCard() const;
	const int GetTotalRedCard() const;
	const int GetYellowCard() const;
	const int GetTotalYellowCard() const;
	const int GetTotalDisciplinePoints() const;

	const int GetNumSeason(const int i_status) const;
	const int GetAge() const;
	const int GetPlayerAge() const;
	const int GetTrainerAge() const;

	bool IsRetired() const;
	bool IsPlayer() const;
	bool IsTrainer() const;
	int GetStatus() const;
	int GetStatus(const int i_numSeason) const;
	bool WasStatus(const int i_numSeason, const int i_status) const;
	void SetStatus(const int i_status);
	const int GetRetirementYear(const int i_status) const;
	const int GetRetirementAge(const int i_status) const;
	void SetRetirementYear(const int i_status);
	const int GetStartingYear() const {return m_startingYear;}
	const int GetBirthYear() const {return m_birthYear;}

	bool IsBusy(const int i_status) const;
	void SetBusy(const bool i_isBusy);

	virtual	ZStream& Serialize(ZStream& o_stream) const;
	virtual ZStream& Deserialize(ZStream& i_stream);

private:
	PeopleHistoryRecordVec m_records;
	static int s_currentYear;

	int m_status;
	bool m_isBusy;
	int m_birthYear;
	int m_startingYear;
	int m_playerRetirementYear;
	int m_trainerRetirementYear;

	const STD::pair<size_t,size_t> GetIndexYearRange(const size_t first, const size_t last) const;

	friend class People;
	friend class PeopleManager;
};

#include "PeopleHistory.inl"
